/*
 * Copyright (c) 2002-2003 by OpenSymphony
 * All rights reserved.
 */
package org.jackysoft.entity;






import org.dom4j.Element;
import org.jackysoft.bean.define.EntitySchemas;

/**
 * @author <a href="mailto:plightbo@hotmail.com">Pat Lightbody</a>
 */



public class ResultNode extends AbstractNode {
	// ~ Instance fields
	// ////////////////////////////////////////////////////////

	/**
	 * 
	 */
	private static final long serialVersionUID = 9189987133267776441L;
	protected PostFunctionsNode postFunction;
	protected PreFunctionsNode preFunction;
	protected String view;
	protected String dueDate;
	protected String oldStatus = "Finished";
	protected String owner;
	protected String status = "Underway";
	protected int join;
	protected int split;
	protected int step;

	// ~ Constructors
	// ///////////////////////////////////////////////////////////

	public ResultNode() {
		super();
		// TODO Auto-generated constructor stub
	}

	// ~ Methods
	// ////////////////////////////////////////////////////////////////

	public ResultNode(Element element) {
		super(element);
	}

	@Override
	public Element asElement() {

		Element root = elementof("unconditional-result");
		attr(root, "id", (id));
		attr(root, "view", view);
		attr(root, "due-date", dueDate);
		attr(root, "old-status", oldStatus);
		attr(root, "owner", owner);
		attr(root, "status", status);

		if (step != 0) {
			attr(root, "step", step);
		} else if (join != 0) {
			attr(root, "join", join);
		} else if (split != 0) {
			attr(root, "split", split);
		}
		addchild(root, this.postFunction);
		addchild(root, this.preFunction);
		return root;
	}

	public String getDueDate() {
		return dueDate;
	}

	
	public int getJoin() {
		return join;
	}

	public String getOldStatus() {
		return oldStatus;
	}

	public String getOwner() {
		return owner;
	}

	
	
	public PostFunctionsNode getPostFunction() {
		return postFunction;
	}

	
	
	public PreFunctionsNode getPreFunction() {
		return preFunction;
	}

	
	public int getSplit() {
		return split;
	}

	public String getStatus() {
		return status;
	}

	public int getStep() {
		return step;
	}

	public String getView() {
		return view;
	}

	@Override
	protected void init(Element root) {
		view = stringAttr(root, "view");
		dueDate = stringAttr(root, "due-date");
		oldStatus = stringAttr(root, "old-status");
		owner = stringAttr(root, "owner");
		status = stringAttr(root, "status");
		join = intAttr(root, "join");
		split = intAttr(root, "split");
		step = intAttr(root, "step");
		this.postFunction = childof(root, "post-functions",
				PostFunctionsNode.class);
		this.preFunction = childof(root, "pre-functions",
				PreFunctionsNode.class);

	}

	public void setDueDate(String dueDate) {
		this.dueDate = dueDate;
	}

	public void setJoin(int join) {
		this.join = join;
	}

	public void setOldStatus(String oldStatus) {
		this.oldStatus = oldStatus;
	}

	public void setOwner(String owner) {
		this.owner = owner;
	}

	public void setPostFunction(PostFunctionsNode postFunctions) {
		this.postFunction = postFunctions;
	}

	public void setPreFunction(PreFunctionsNode preFunction) {
		this.preFunction = preFunction;
	}

	public void setSplit(int split) {
		this.split = split;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public void setStep(int step) {
		this.step = step;
	}

	public void setView(String view) {
		this.view = view;
	}

	@Override
	public String tagName() {
		// TODO Auto-generated method stub
		return "unconditional-result";
	}

}
